<template>
    <div>
        <h1>用户登录</h1>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">账号</td>
                    <td>
                        <input type="text" v-model="queryInfo.username">
                    </td>
                </tr>

                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="queryInfo.pwd">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-primary" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios';
const router = useRouter()
const route = useRoute()


const queryInfo = reactive({
    username:'',
    pwd:''
})


const login = () => {
    axios({
        url:'/api/User/Login',
        method:'get',
        params:queryInfo
    })
    .then((res) => {
        console.log(res);
        if(res.data == -1){
            alert('账号错误');
            return;
        }
        else if(res.data == -2){
            alert('密码错误');
            return;
        }
        else{
            alert('登录成功');
            router.push('/userlist')
        }
    })
}

</script>

<style scoped>
h1{
    text-align: center;
    color: red;
}
</style>